package com.feisuanyz.controller;

import com.feisuanyz.dto.EventQuery;
import com.feisuanyz.dto.RestResult;
import com.feisuanyz.service.EventService;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/events")
@Slf4j
public class EventController {

    @Autowired
    private EventService eventService;

    @PostMapping("/create")
    public ResponseEntity<RestResult<Void>> createEvent(@Valid @RequestBody EventQuery eventQuery) {
        RestResult<Void> result = eventService.createEvent(eventQuery);
        return ResponseEntity.ok(result);
    }

    @PutMapping("/edit")
    public ResponseEntity<RestResult<Void>> editEvent(@Valid @RequestBody EventQuery eventQuery) {
        RestResult<Void> result = eventService.editEvent(eventQuery);
        return ResponseEntity.ok(result);
    }

    @DeleteMapping("/delete/{eventId}")
    public ResponseEntity<RestResult<Void>> deleteEvent(@PathVariable Integer eventId, @RequestParam Integer deleteBy) {
        RestResult<Void> result = eventService.deleteEvent(eventId, deleteBy);
        return ResponseEntity.ok(result);
    }
}